/*
	Copyright (C) 2010 Salil Bhagurkar

	This file is part of k3

	k3 is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	k3 is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with k3.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef DPRINT_H_
#define DPRINT_H_

/**
 * Debug printing functionality that uses printk but filters shit
 */

//Debug levels
#define D_FREQ 0, COMPILER_FUNCTION_NAME //Enable frequent data that will make the screen look pukish
#define D_INFO 1, COMPILER_FUNCTION_NAME //Information output
#define D_PROG 2, COMPILER_FUNCTION_NAME //Progress output
#define D_ALERT 3, COMPILER_FUNCTION_NAME //Alert
#define D_OFF 10, ""

#define D_LEVEL_FREQ 0
#define D_LEVEL_INFO 1
#define D_LEVEL_PROG 2
#define D_LEVEL_ALERT 3
#define D_LEVEL_OFF 10

void dprint_set_debug(u32 level, char *filter0, char *filter1, u32 delay);
void dprint_base(u32 level, const char *function_name, const char *subject, const char *fmt, ...);

#define dprint dprint_base


/**
Function to check if the passed pointer is valid. If not, print a message for debugging
*/
static int __validate_pointer(const char *fn_name, void *x, const char *var_name)
{
	if(!x) {
		dprint(D_LEVEL_ALERT, fn_name, var_name, "Null pointer");
		return EPINV;
	}
	return 0;
}

//Check if a variable is null, return EPINV
#define D_CHECK_NULL(x, var_name) if(__validate_pointer(COMPILER_FUNCTION_NAME, x, var_name)) return EPINV

//Check if a variable is null, return NULL
#define D_PTR_CHECK_NULL(x, var_name) if(__validate_pointer(COMPILER_FUNCTION_NAME, x, var_name)) return NULL


int printk(const char *fmt, ...);
int printmem(void *start, u32 len);
int printwords(void *start, u32 count);
int printerror(int err);


#endif /* DPRINT_H_ */
